﻿////////////////////////////////////////////////////////////////////////////////////////////
// File: PGravity.cs                                                                      //
// Author: Mike Binnix                                                                    //
// Desc: Force generator to simulate gravity.  This is normally unneeded in simple        //
//       simulations.  Can be overwritten for times when more complex gravitational       //
//       effects are needed.  Such as when the gravitational force depends on the         //
//       distance to the object.                                                          //
////////////////////////////////////////////////////////////////////////////////////////////

using Microsoft.Xna.Framework;

namespace SlothEngine.Physics.Forces
{
    public class PGravity : IPForceGenerator
    {
        #region Attributes
        protected Vector2 gravity;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the gravity value.
        /// </summary>
        public Vector2 Gravity
        {
            get
            {
                return gravity;
            }
            set
            {
                gravity = value;
            }
        }
        #endregion

        #region Constructors
        public PGravity(Vector2 gravity)
        {
            this.gravity = gravity;
        }
        public PGravity(float x, float y)
        {
            gravity.X = x;
            gravity.Y = y;
        }
        #endregion

        #region Methods
        /// <summary>
        /// Applies the gravitational force if object is able to move.
        /// </summary>
        /// <param name="gameTime">Time since last update.</param>
        /// <param name="particle">particle to change.</param>
        public virtual void Update(GameTime gameTime, XNAParticle particle)
        {
            if (!particle.CanMove)
                particle.AddForce(Vector2.Zero);
            else
                particle.AddForce(gravity * particle.Mass);
        }
        #endregion
    }
}
